﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
namespace UI.ViewModel
{
    [PropertyChanged.AddINotifyPropertyChangedInterface]
  public  class HomeViewModel:ViewModelBase
    {

        Model.DataContext Context = new Model.DataContext();

        public   HomeViewModel()
        {
            LoadData();
        }



        public async void LoadData()
        {
            OwnerCount = await Context.DB.Queryable<Model.Owner>().CountAsync();
            RoomCount =   Context.DB.Queryable<Model.Rooms>().Count();
            CarCount =  Context.DB.Queryable<Model.OwnerCar>().Count();
            ParkingSpaceCount =  Context.DB.Queryable<Model.Car_ParkingSpace>().Count();


            var FirstDayOnMount = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;
            var LastDayOnMount = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);
            UseElecAmount =  Context.DB.Queryable<Model.F_CostRoom>().Where(c =>c.CostType=="电费" && c.CreateTime>= FirstDayOnMount && c.CreateTime <=LastDayOnMount).Sum(c=>c.Amount);
            UseGasAmount =  Context.DB.Queryable<Model.F_CostRoom>().Where(c =>c.CostType=="天然气" && c.CreateTime>= FirstDayOnMount && c.CreateTime <=LastDayOnMount).Sum(c => c.Amount);
            UseWaterAmount =  Context.DB.Queryable<Model.F_CostRoom>().Where(c =>c.CostType=="水费" && c.CreateTime>= FirstDayOnMount && c.CreateTime <=LastDayOnMount).Sum(c => c.Amount);

            WuyeFei =Context.DB.Queryable<Model.PmFeeBill>().Where(c =>   c.Date >= FirstDayOnMount && c.Date <= LastDayOnMount).Sum(c => c.ShishouAmount);

        }
        public int OwnerCount { get; set; }
        public int RoomCount { get; set; }
        public int CarCount { get; set; }
        public int ParkingSpaceCount { get; set; }

        public decimal UseElecAmount { get; set; }
        public decimal UseGasAmount { get; set; }
        public decimal UseWaterAmount { get; set; }
        public decimal UseHeatingAmount { get; set; }
        public decimal WuyeFei { get; set; }
    }
}
